Jan-Philipp Kolb
28 April 2017
Modularer Aufbau
R ist frei verfügbar. Es kann umsonst runtergeladen werden.
Gute Möglichkeiten für die Visualisierung (Link )
R wird immer populärer
pic
Import
https://github.com/Japhilko/RInterfaces
Es lohnt sich immer wieder zu dieser Seite zurückzukehren, weil hier alle relevanten Dokumente verlinkt sind.
Grundsätzlich bietet es sich an, den einzelnen Teilen der Veranstaltung mit dem File zu folgen, dass mit dem Begriff Browser verlinkt ist.
Zum Ausdrucken eignen sich die pdf-Dateien besser.
Diese können mit dem Raw Button heruntergeladen werden.
Raw Button zum Download
Begleitend zu den Folien wird meistens auch ein R-File angeboten.
Hier können Sie entweder das gesamte R-File herunterladen und in R ausführen oder einzelne Befehle per Copy/Paste übernehmen.
Vereinzelt sind auch Datensätze vorhanden.
.csv Dateien können direkt von R eingelesen werden (wie das geht werde ich noch zeigen).
Wenn die .csv Dateien heruntergeladen werden sollen auch den Raw Button verwenden.
Alle anderen Dateien (bspw. .RData) auch mittels Raw Button herunterladen.
Zusätzlich gibt es für jedes Kapitel eine Aufgabe, da man nur durch eigenes Trainieren auf der Lernkurve vorankommt.
Die Links sind nur im HTML Dokument zu sehen aber auch in der pdf vorhanden
R unterstützt von Haus aus schon einige wichtige Formate:
read.csv()read.fwf()read.delim()Import Button
https://data.montgomerycountymd.gov/api/views/6rqk-pdub/rows.csv?accessType=DOWNLOAD
So findet man heraus, in welchem Verzeichnis man sich gerade befindet
getwd()So kann man das Arbeitsverzeichnis ändern:
Man erzeugt ein Objekt in dem man den Pfad abspeichert:
main.path <- "C:/" # Beispiel für Windows
main.path <- "/users/Name/" # Beispiel für Mac
main.path <- "/home/user/" # Beispiel für LinuxUnd ändert dann den Pfad mit setwd()
setwd(main.path)Bei Windows ist es wichtig Slashs anstelle von Backslashs zu verwenden.
library(foreign) ist für den Import von fremden Datenformaten nötigread.csv() genutzt werden um die Daten einzulesen.read.csv2() wegen der Komma-Separierung braucht.library(foreign)
?read.csv
?read.csv2Zunächst muss das Arbeitsverzeichnis gesetzt werden, in dem sich die Daten befinden:
Dat <- read.csv("schuldaten_export.csv")Wenn es sich um Deutsche Daten handelt:
Dat <- read.csv2("schuldaten_export.csv")url <- "https://raw.githubusercontent.com/Japhilko/
GeoData/master/2015/data/whcSites.csv"
whcSites <- read.csv(url) Dateien können auch direkt aus dem Internet geladen werden:
link<- "http://www.statistik.at/web_de/static/
mz_2013_sds_-_datensatz_080469.sav"
?read.spss
Dat <- read.spss(link,to.data.frame=T)fileXls <- "data/newFile.xlsx"
unlink(fileXls, recursive = FALSE, force = FALSE)
exc <- loadWorkbook(fileXls, create = TRUE)
createSheet(exc,'Input')
saveWorkbook(exc)input <- data.frame('inputType'=c('Day','Month'),'inputValue'=c(2,5))
writeWorksheet(exc, input, sheet = "input", startRow = 1, startCol = 2)
saveWorkbook(exc)myFunction <- function(){
aa <- rnorm(200)
bb <- rnorm(200)
res <- lm(aa~bb)$res
return(res)
}Markdown ist eine sehr einfache Syntax, die es Benutzern erlaubt, aus einfachen Textdateien gut gelayoutete Dokumente zu erstellen.
**fettes Beispiel**
*kursives Beispiel*
~~durchgestrichen~~
- Aufzählungspunkt
fettes Beispiel
kursives Beispiel
durchgestrichen
### Überschrift Ebene 3
#### Überschrift Ebene 4
[Meine Github Seite](https://github.com/Japhilko)


n=100Ein inline Codeblock: 100
| Argument | Beschreibung |
|---|---|
| eval | Soll Rcode evaluiert werden? |
| warning | Sollen Warnings angezeigt werden? |
| cache | Soll der Output gespeichert werden? |
knitrinstall.packages("knitr")library("knitr")kable um Tabellen zu erzeugenkable erzeugena <- runif(10)
b <- rnorm(10)
ab <- cbind(a,b)
kable(ab)| a | b |
|---|---|
| 0.4187260 | -0.0208481 |
| 0.1080964 | 0.7370236 |
| 0.7462707 | -1.5531820 |
| 0.2663426 | -1.0163409 |
| 0.3797959 | 0.6224963 |
| 0.8080904 | 0.5387171 |
| 0.6135115 | 0.2033197 |
| 0.1821460 | 1.0501195 |
| 0.9535168 | -0.5623560 |
| 0.2891734 | -0.4959585 |
cache=T angegeben ist, wird das Ergebnis des Chunks abgespeichert---
title: "Intro - Erste Schritte"
author: "Jan-Philipp Kolb"
date: "10 April 2017"
output:
beamer_presentation:
colortheme: beaver
theme: CambridgeUS
---
output:
beamer_presentation:
toc: yes
\Sexpr{}
citation() bekommt man sehr schnell die Referenzcitation("RMySQL")##
## To cite package 'RMySQL' in publications use:
##
## Jeroen Ooms, David James, Saikat DebRoy, Hadley Wickham and
## Jeffrey Horner (2017). RMySQL: Database Interface and 'MySQL'
## Driver for R. R package version 0.10.11.
## https://CRAN.R-project.org/package=RMySQL
##
## A BibTeX entry for LaTeX users is
##
## @Manual{,
## title = {RMySQL: Database Interface and 'MySQL' Driver for R},
## author = {Jeroen Ooms and David James and Saikat DebRoy and Hadley Wickham and Jeffrey Horner},
## year = {2017},
## note = {R package version 0.10.11},
## url = {https://CRAN.R-project.org/package=RMySQL},
## }
---
title: "R Schnittstellen"
author: "Jan-Philipp Kolb"
date: "21 April 2017"
output:
pdf_document: default
bibliography: Rschnittstellen.bib
---
## [1] "Fri Apr 28 10:00:18 2017"
$$
\begin{equation}\label{eq2}
t_{i}=\sum\limits_{k=1}^{M_{i}}{y_{ik}}=M_{i}\bar{Y}_{i}.
\end{equation}
$$
Folie mit zwei Spalten
====================================
Erste Spalte
***
Zweite Spalte
transition: rotate
Ein neues Kapitel einfügen
====================================
type: section
Anderer Folientyp
====================================
type: prompt
Noch ein anderer Folientyp
====================================
type: alert
Meine Präsentation
========================================
author: Jan-Philipp Kolb
font-family: 'Impact'
Meine Präsentation
========================================
author: Jan-Philipp Kolb
font-import: http://fonts.googleapis.com/css?family=Risque
font-family: 'Risque'
Normale Schriftgröße
<small>This sentence will appear smaller.</small>

---
title: "ioslides Beispiel"
author: "Jan-Philipp Kolb"
date: "20 April 2017"
output:
ioslides_presentation:
logo: figure/Rlogo.png
---
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
|---|---|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 |
| 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 |
| 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
Um den Präsentationstyp zu ändern kann man das CSS verändern
import sys
print(sys.version)## 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:01:18) [MSC v.1900 32 bit (Intel)]
jupyter notebook
url <- "https://raw.githubusercontent.com/Japhilko/
GeoData/master/2015/data/whcSites.csv"
whcSites <- read.csv(url) magrittr - für den Pipe Operator in R:
library("magrittr")leaflet - um interaktive Karten mit der JavaScript Bibliothek ‘Leaflet’ zu erzeugen
library("leaflet")m <- leaflet() %>%
addTiles() %>% # Add default OpenStreetMap map tiles
addMarkers(lng=whcSites$lon,
lat=whcSites$lat,
popup=whcSites$name_en)
mpic
whcSites$color <- "red"
whcSites$color[whcSites$category=="Cultural"] <- "blue"
whcSites$color[whcSites$category=="Mixed"] <- "orange"m1 <- leaflet() %>%
addTiles() %>%
addCircles(lng=whcSites$lon,
lat=whcSites$lat,
popup=whcSites$name_en,
color=whcSites$color)Weltkulturerbe
leaflet() %>%
addTiles() %>%
addMarkers(data = coffee_shops, group = "Food & Drink") %>%
addMarkers(data = restaurants, group = "Food & Drink") %>%
addMarkers(data = restrooms, group = "Restrooms")library(sp)
Sr1 = Polygon(cbind(c(2, 4, 4, 1, 2), c(2, 3, 5, 4, 2)))
Sr2 = Polygon(cbind(c(5, 4, 2, 5), c(2, 3, 2, 2)))
Sr3 = Polygon(cbind(c(4, 4, 5, 10, 4), c(5, 3, 2, 5, 5)))
Sr4 = Polygon(cbind(c(5, 6, 6, 5, 5), c(4, 4, 3, 3, 4)), hole = TRUE)
Srs1 = Polygons(list(Sr1), "s1")
Srs2 = Polygons(list(Sr2), "s2")
Srs3 = Polygons(list(Sr4, Sr3), "s3/4")
SpP = SpatialPolygons(list(Srs1, Srs2, Srs3), 1:3)
leaflet(height = "300px") %>% addPolygons(data = SpP)library(maps)
mapStates = map("state", fill = TRUE, plot = FALSE)
leaflet(data = mapStates) %>% addTiles() %>%
addPolygons(fillColor = topo.colors(10, alpha = NULL), stroke = FALSE)m <- leaflet() %>% setView(lng = -71.0589, lat = 42.3601, zoom = 12)
m %>% addTiles()m %>% addProviderTiles("Stamen.Toner")m %>% addProviderTiles("CartoDB.Positron")m %>% addProviderTiles("Esri.NatGeoWorldMap")m %>% addProviderTiles("OpenTopoMap")m %>% addProviderTiles("Thunderforest.OpenCycleMap")leaflet() %>% addTiles() %>% setView(-93.65, 42.0285, zoom = 4) %>%
addWMSTiles(
"http://mesonet.agron.iastate.edu/cgi-bin/wms/nexrad/n0r.cgi",
layers = "nexrad-n0r-900913",
options = WMSTileOptions(format = "image/png", transparent = TRUE),
attribution = "Weather data © 2012 IEM Nexrad"
)m %>% addProviderTiles("MtbMap") %>%
addProviderTiles("Stamen.TonerLines",
options = providerTileOptions(opacity = 0.35)) %>%
addProviderTiles("Stamen.TonerLabels")greenLeafIcon <- makeIcon(
iconUrl = "http://leafletjs.com/examples/custom-icons/leaf-green.png",
iconWidth = 38, iconHeight = 95,
iconAnchorX = 22, iconAnchorY = 94,
shadowUrl = "http://leafletjs.com/examples/custom-icons/leaf-shadow.png",
shadowWidth = 50, shadowHeight = 64,
shadowAnchorX = 4, shadowAnchorY = 62
)
leaflet(data = quakes[1:4,]) %>% addTiles() %>%
addMarkers(~long, ~lat, icon = greenLeafIcon)leaflet(quakes) %>% addTiles() %>% addMarkers(
clusterOptions = markerClusterOptions()
)leaflet() %>% addTiles() %>%
addRectangles(
lng1=-118.456554, lat1=34.078039,
lng2=-118.436383, lat2=34.062717,
fillColor = "transparent"
)Überblick über Möglichkeiten des Parallel Computings - Paket parallel